<template>
  <view class="repairs-container">
    <view class="repairs-list">
      <view v-for="(repair, index) in repairs" :key="index" class="repair-item">
        <view class="repair-header">
          <text class="repair-time">{{ repair.createTime }}</text>
          <text :class="['repair-status', repair.status]">{{ getStatusText(repair.status) }}</text>
        </view>
        <view class="repair-content" @click="viewDetail(repair.id)">
          <text class="repair-title">{{ repair.title }}</text>
          <text class="repair-desc">{{ repair.description }}</text>
        </view>
      </view>
    </view>
    
    <view v-if="repairs.length === 0" class="empty-state">
      <text>暂无报修记录</text>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      repairs: [
        {
          id: 1,
          title: '水管漏水维修',
          description: '厨房水槽下方的水管出现渗漏现象',
          createTime: '2025-03-13 10:30',
          status: 'pending'
        }
      ]
    }
  },
  
  onLoad() {
    // this.fetchRepairHistory()
  },
  
  methods: {
    async fetchRepairHistory() {
      try {
        // 从后端获取报修历史数据
        const res = await this.$api.getRepairHistory()
        this.repairs = res.data
      } catch (error) {
        uni.showToast({
          title: '获取数据失败',
          icon: 'none'
        })
      }
    },
    
    getStatusText(status) {
      const statusMap = {
        'pending': '待处理',
        'processing': '处理中',
        'completed': '已完成',
        'cancelled': '已取消'
      }
      return statusMap[status] || status
    },
    
    viewDetail(id) {
      uni.navigateTo({
        url: `/pages/my/repair-detail?id=${id}`
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.repairs-container {
  padding: 20rpx;
  
  .repairs-list {
    .repair-item {
      background: #fff;
      border-radius: 12rpx;
      padding: 20rpx;
      margin-bottom: 20rpx;
      
      .repair-header {
        display: flex;
        justify-content: space-between;
        margin-bottom: 16rpx;
        
        .repair-time {
          color: #999;
          font-size: 24rpx;
        }
        
        .repair-status {
          font-size: 24rpx;
          
          &.pending { color: #ff9900; }
          &.processing { color: #2979ff; }
          &.completed { color: #19be6b; }
          &.cancelled { color: #999; }
        }
      }
      
      .repair-content {
        .repair-title {
          font-size: 28rpx;
          font-weight: bold;
          margin-bottom: 8rpx;
        }
        
        .repair-desc {
          font-size: 26rpx;
          color: #666;
        }
      }
    }
  }
  
  .empty-state {
    text-align: center;
    padding: 60rpx 0;
    color: #999;
  }
}
</style>
